<template>
  <div class="lay-container" :style="{ width }">
    <el-menu :default-active="route.path" router :collapse="isCollapsed">
      <!-- 添加 router 属性 -->
      <h3 class="menu-title" v-if="!isCollapsed">{{props.title}}</h3>
      <el-menu-item v-for="item in menuItems" :key="item.path" :index="item.path" :disabled="isCollapsed">
        <el-icon>
          <component :is="item.icon" />
        </el-icon>
        <span>{{ item.title }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { useRoute } from "vue-router";
// 引入使得侧边栏开启关闭的显示变量  为了统一管理 我使用的是pinia
import { useUIStore } from '@/stores/UI'
import { storeToRefs } from "pinia";
import { computed } from "vue";
const Uistore = useUIStore()
const { isCollapsed } = storeToRefs(Uistore)
const route = useRoute();
// 为了使得结构简化 这里使用数组来遍历菜单项 这里就不写下拉的 el-sub-menu了
const menuItems = [
  {
    path: "/home",
    icon: "House",
    title: "首页",
  },
  {
    path: "/goods",
    icon: "Document",
    title: "面经管理",
  },
  {
    path: "/user",
    icon: "User",
    title: "用户管理",
  },
  {
    path: "/other",
    icon: "MoreFilled",
    title: "其他",
  },
];
const props = defineProps(['title'])

// width 的动态响应
const width = computed(() => {
  return isCollapsed.value ? "64px" : "200px";
});
</script>

<style scoped lang="scss">
// 侧边栏
.lay-container {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-right: 1px solid #e4e7ed;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  height: 100vh;
  top: 0;
  transition: all 0.3s ease-in-out;
  overflow: hidden;

  .el-menu {
    border: none;
    padding: 16px 0;
    background: transparent;
    transition: all 0.3s ease-in-out;

    .menu-title {
      text-align: center;
      color: #fff;
      font-size: 18px;
      font-weight: bold;
      margin: 20px 0 30px;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      transition: all 0.3s ease-in-out;
      opacity: 1;
    }

    .el-menu-item {
      height: 48px;
      line-height: 48px;
      margin: 8px 12px;
      border-radius: 8px;
      transition: all 0.3s ease;
      color: rgba(255, 255, 255, 0.8);
      white-space: nowrap;
      overflow: hidden;

      .el-icon {
        color: rgba(255, 255, 255, 0.8);
        font-size: 18px;
        transition: all 0.3s ease;
        margin-right: 12px;
      }

      span {
        font-weight: 500;
        transition: all 0.3s ease;
        opacity: 1;
      }

      &:hover {
        background-color: rgba(255, 255, 255, 0.15);
        color: #fff;
        transform: translateX(5px);

        .el-icon {
          color: #fff;
        }
      }

      &.is-active {
        background: linear-gradient(45deg, #ff6b6b, #feca57);
        color: #fff;

        .el-icon {
          color: #fff;
        }
      }
    }
  }
}
.el-menu--collapse {
opacity: 0;

}
</style>
